import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { createPinia } from 'pinia'
import i18n from './i18n'

const app = createApp(App)

// 注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 全局错误处理
app.config.errorHandler = (err, vm, info) => {
  console.error('全局错误:', err);
  console.log('错误组件:', vm);
  console.log('错误信息:', info);
  
  // 防止某些错误导致整个应用崩溃
  return false;
};

// 全局警告处理
app.config.warnHandler = (msg, vm, trace) => {
  console.warn('全局警告:', msg);
  console.log('警告组件:', vm);
  console.log('警告追踪:', trace);
  
  // 防止某些警告影响用户体验
  return false;
};

app.use(router)
app.use(ElementPlus)
app.use(createPinia())
app.use(i18n)

app.mount('#app')
